--Fix: ahora también se ve en los courses n_n

local player = ...
assert(player)

local t = Def.ActorFrame {}

--custom fonts jojo
--lo que hace el ingenio :D
t[#t+1] = LoadFont("_SpecialTyphos")..{
	Name="meterubaru_tekesutu";
	InitCommand=cmd(shadowlength,0);
	SetCommand=function(self)
		--Se necesita el meter de los pasos actuales
		local meter = GAMESTATE:GetCurrentTrail(player) or GAMESTATE:GetCurrentSteps(player)
		meter = meter:GetMeter()
		local mbtx = ""
		local char
		--Meter menos de 25
		if meter < 25 then
			--imagen para la meterbar
			--un caracter ps
			if meter >= 17 then
				char = "#"
			else
				if meter >= 9 then
					char = "*"
				else
					char = "@"
				end
			end
			--chars según meter (max 8)
			mbtx = string.rep(char,((meter-1)%8)+1)
		else
			--Meter es más de 25 (sirve para poner diff desconocida)
			mbtx = string.rep("?",8)
		end
		--cmd's
		self:settext(mbtx);
		(cmd(stoptweening;zoom,0;sleep,0.3;zoom,1))(self);
		if meter >= 22 then
			self:glowshift();
			self:effectperiod(0.5);
			self:effectcolor1(color("#FF0000AA"));
			self:effectcolor2(color("#FFFFFF00"));
		else
			self:stopeffect();
		end
	end;
	CurrentStepsP1ChangedMessageCommand=function(self)
		if player == PLAYER_1 then
			self:playcommand("Set");
		end;
	end;
	CurrentStepsP2ChangedMessageCommand=function(self)
		if player == PLAYER_2 then
			self:playcommand("Set");
		end;
	end;
	CurrentTrailP1ChangedMessageCommand=function(self)
		if player == PLAYER_1 then
			self:playcommand("Set");
		end;
	end;
	CurrentTrailP2ChangedMessageCommand=function(self)
		if player == PLAYER_2 then
			self:playcommand("Set");
		end;
	end;
}

t[#t+1] = LoadFont("score")..{
	--Text="0123456789";
	InitCommand=cmd(shadowlength,0;y,30);
	SetCommand=function(self)
		local meter = GAMESTATE:GetCurrentTrail(player) or GAMESTATE:GetCurrentSteps(player)
		meter = meter:GetMeter()
		--Help, quiero los qmarks "??" para la misma fuente x_x
		if meter >= 25 then meter = 0 end
		self:settext(string.format("%02i",meter));
		(cmd(stoptweening;zoom,0;sleep,0.3;zoom,1))(self);
		--self:diffuse(MeterColor2(meter));
	end;
	CurrentStepsP1ChangedMessageCommand=function(self)
		if player == PLAYER_1 then
			self:playcommand("Set");
		end;
	end;
	CurrentStepsP2ChangedMessageCommand=function(self)
		if player == PLAYER_2 then
			self:playcommand("Set");
		end;
	end;
	CurrentTrailP1ChangedMessageCommand=function(self)
		if player == PLAYER_1 then
			self:playcommand("Set");
		end;
	end;
	CurrentTrailP2ChangedMessageCommand=function(self)
		if player == PLAYER_2 then
			self:playcommand("Set");
		end;
	end;
}

t.VisibleCommand=function(self)
	if GAMESTATE:GetCurrentSong() or GAMESTATE:GetCurrentCourse() then self:visible(true) return end;
	self:visible(false);
end

--Meter visible para courses tambien :D
t.CurrentSongChangedMessageCommand=cmd(playcommand,"Visible");
t.CurrentCourseChangedMessageCommand=cmd(playcommand,"Visible");

t.PlayerJoinedMessageCommand=cmd(playcommandonchildren,"Children")
t.InitCommand=cmd(playcommandonchildren,"Children")

t.ChildrenCommand=function(self)
	self:horizalign(GAMESTATE:GetNumPlayersEnabled() == 1 and center or (player == PLAYER_1 and right or left));
end

return t